package com.ruoyi.webs.utils;

import java.math.BigDecimal;

public class MathUtils {
    public static double doubleSub(double d1, double d2) {
        BigDecimal bd1 = new BigDecimal(Double.toString(d1));
        BigDecimal bd2 = new BigDecimal(Double.toString(d2));
        return bd1.subtract(bd2).doubleValue();
    }

    public static double doubleAdd(double d1, double d2) {
        BigDecimal bd1 = new BigDecimal(Double.toString(d1));
        BigDecimal bd2 = new BigDecimal(Double.toString(d2));
        return bd1.add(bd2).doubleValue();
    }

    public static String longPersent(Long totalPerson, Long policyTotalPerson) {
        if (totalPerson == null) {
            return "0.0%";
        }
        String plainString = "0.0%";
        BigDecimal totalPersonDecimal = new BigDecimal(totalPerson.longValue());
        BigDecimal policyTotalPersonDecimal = new BigDecimal(policyTotalPerson.longValue());
        if (totalPersonDecimal.compareTo(new BigDecimal(0L)) > 0) {
            BigDecimal divide = policyTotalPersonDecimal.divide(totalPersonDecimal, 5, 4);
            BigDecimal setScale = divide.multiply(new BigDecimal(100)).setScale(2, 4);
            plainString = String.valueOf(setScale.toPlainString()) + "%";
        }
        return plainString;
    }

    public static String longPersentThouthand(Long totalPerson, Long policyTotalPerson) {
        if (totalPerson == null) {
            return "0.0‰";
        }
        String plainString = "0.0‰";
        BigDecimal totalPersonDecimal = new BigDecimal(totalPerson.longValue());
        BigDecimal policyTotalPersonDecimal = new BigDecimal(policyTotalPerson.longValue());
        if (totalPersonDecimal.compareTo(new BigDecimal(0L)) > 0) {
            BigDecimal divide = policyTotalPersonDecimal.divide(totalPersonDecimal, 7, 4);
            BigDecimal setScale = divide.multiply(new BigDecimal(1000)).setScale(2, 4);
            plainString = String.valueOf(setScale.toPlainString()) + "‰";
        }
        return plainString;
    }

    public static String persentDouble(BigDecimal num, BigDecimal alllMoney) {
        if (alllMoney.doubleValue() == 0.0D) {
            return "0.0%";
        }
        String plainString = "0.0%";
        if (num.compareTo(new BigDecimal("0.00")) > 0) {
            BigDecimal divide = num.divide(alllMoney, 5, 4);
            BigDecimal setScale = divide.multiply(new BigDecimal(100)).setScale(2, 4);
            plainString = String.valueOf(setScale.toPlainString()) + "%";
        }
        return plainString;
    }

    public static String persentDouble(double num, double alllMoney) {
        BigDecimal bd1 = new BigDecimal(Double.toString(num));
        BigDecimal bd2 = new BigDecimal(Double.toString(alllMoney));
        if (alllMoney == 0.0D) {
            return "0.0%";
        }
        String plainString = "0.0%";
        if (num > 0.0D) {
            BigDecimal divide = bd1.divide(bd2, 5, 4);
            BigDecimal setScale = divide.multiply(new BigDecimal(100)).setScale(2, 4);
            plainString = String.valueOf(setScale.toPlainString()) + "%";
        }
        return plainString;
    }

    public static String persentDoublethoud(double num, double alllMoney) {
        BigDecimal bd1 = new BigDecimal(Double.toString(num));
        BigDecimal bd2 = new BigDecimal(Double.toString(alllMoney));
        if (alllMoney == 0.0D) {
            return "0.0‰";
        }
        String plainString = "0.0‰";
        if (num > 0.0D) {
            BigDecimal divide = bd1.divide(bd2, 7, 4);
            BigDecimal setScale = divide.multiply(new BigDecimal(1000)).setScale(2, 4);
            plainString = String.valueOf(setScale.toPlainString()) + "‰";
        }
        return plainString;
    }
}


/* Location:              E:\hlhzxh.war!\WEB-INF\classes\com\hlkj\module\\utils\MathUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */